/*
Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.
*/

class Solution {
public:
    vector<int> plusOne(vector<int> &digits) {
        int remainder = 1;
        for (int i = digits.size()-1; i>=0 && remainder>0; i--) {
            int digit = digits[i] + remainder;
            digits[i] = digit % 10;
            remainder = digit/10;
        }
        if (remainder) digits.insert(digits.begin(), remainder);
        return digits;
    }
};
